package com.itheima.sfbx.insurance.handler.impl;

import com.itheima.sfbx.framework.commons.constant.insure.InsureConstant;
import com.itheima.sfbx.insurance.dto.CustomerRelationVO;
import com.itheima.sfbx.insurance.dto.DoInsureVo;
import com.itheima.sfbx.insurance.handler.InsureHandler;
import com.itheima.sfbx.insurance.service.ICustomerRelationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @ClassName AccidentInsureHandler.java
 * @Description 保障型意外类：保险投保、创建订单、保费计算
 */
@Slf4j
@Service
public class AccidentInsureHandler extends SafeguardInsureHandler implements InsureHandler {

    @Resource
    private ICustomerRelationService customerRelationService;//客户关系表服务


    @Override
    public String doPremium(DoInsureVo doInsureVo) {
        //查询被保人
        CustomerRelationVO customerRelationVO = customerRelationService.findById(doInsureVo.getCustomerRelationIds().get(0));//获取第一个关系
        log.warn("当前 保障型意外类,为被保人：{}", customerRelationVO);
        if (customerRelationVO != null){
            //获取被保人收入
            BigDecimal income = customerRelationVO.getIncome();
            log.warn("被保人收入：{}", income);
            if (income != null && income.compareTo(new BigDecimal(10000000)) > 0){
                //判断被保人的月收入是否高于10000万或者没有填写的人直接抛出异常
                throw new RuntimeException("月收入高于10000万");
            }
            //判断被保人的月收入是否高于10000万或者没有填写的人直接抛出异常

        }
        return super.doPremium(doInsureVo);
    }
}
